package com.shinhye.elephantsafe.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class StreamTools {
	/**
	 * Get String type text from a InputStream.
	 * @param is
	 * @return result
	 * @throws IOException if the stream is closed or another IOException occurs.
	 */
	public static String getStringFromStream(InputStream is) throws IOException {
		byte[] b = new byte[1024];
		int len;
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		while((len = is.read(b)) != -1){
			bos.write(b, 0, len);
		}
		String text = new String(bos.toByteArray());
		bos.close();
		return text;
	}
		
}


